'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	let {account,password} = event
	if(!account) {
		return {
			code: 500,
			data: {},
			message: '请输入帐号！'
		}
	}
	if(!password) {
		return {
			code: 500,
			data: {},
			message: '请输入密码！'
		}
	}
	const collection = db.collection('user')
	const res = await collection.where({
		account,
		password
	}).field({
		account: true,
		name: true,
		photo: true,
		_id: true
	}).get()
	if(res.data.length == 0) {
		return {
			code: 500,
			data: {},
			message: '帐号密码错误！'
		}
	} else {
		return {
			code: 0,
			data: res.data[0],
			message: 'done'
		}
	}
	
	
};

